package com.atguigu.dao.impl;

import com.atguigu.dao.NginxServiceConfigPhpDao;
import com.atguigu.pojo.NginxServiceConfigPhp;

import java.util.List;

public class NginxServiceConfigPhpDaoImpl extends BaseDao implements NginxServiceConfigPhpDao {
    @Override
    public int addNginxServiceConfigPhp(NginxServiceConfigPhp nginxServiceConfigPhp) {
        System.out.println("NginxServiceConfigPhpDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_nginxServiceConfigPhp(`id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId`) values(?,?,?,?,?,?,?,?,?,?);";
            return update(sql,nginxServiceConfigPhp.getId(),nginxServiceConfigPhp.getServerId(),
                    nginxServiceConfigPhp.getServiceId(),nginxServiceConfigPhp.getDeployEnvId(),nginxServiceConfigPhp.getDomain(),
                    nginxServiceConfigPhp.getPort(),nginxServiceConfigPhp.getWorkDirectory(),nginxServiceConfigPhp.getUse(),nginxServiceConfigPhp.getProjectId(),nginxServiceConfigPhp.getProjectModuleId());
    }

    @Override
    public int deleteNginxServiceConfigPhpById(String id) {
        String sql="delete from t_nginxServiceConfigPhp where id=?";
        return update(sql,id);
    }

    @Override
    public int updateNginxServiceConfigPhp(NginxServiceConfigPhp nginxServiceConfigPhp) {
        String sql="update t_nginxServiceConfigPhp set `serverId`=?,`serviceId`=?,`deployEnvId`=?,`domain`=?,`port`=?,`workDirectory`=? ,`use`=?,`projectId`=?,`projectModuleId`=? where id=?";
        return update(sql,nginxServiceConfigPhp.getServerId(),
                nginxServiceConfigPhp.getServiceId(),nginxServiceConfigPhp.getDeployEnvId(),nginxServiceConfigPhp.getDomain(),
                nginxServiceConfigPhp.getPort(),nginxServiceConfigPhp.getWorkDirectory(),nginxServiceConfigPhp.getUse(),nginxServiceConfigPhp.getProjectId(),nginxServiceConfigPhp.getProjectModuleId(),nginxServiceConfigPhp.getId());
    }

    @Override
    public NginxServiceConfigPhp queryNginxServiceConfigPhpById(String id) {
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp where id=?";
        return queryForOne(NginxServiceConfigPhp.class,sql,id);
    }

    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhps() {
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp";
        return queryForList(NginxServiceConfigPhp.class,sql);
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByServiceId(String serviceId){
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp where serviceId =?";
        return queryForList(NginxServiceConfigPhp.class,sql,serviceId);
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByPort(String port) {
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp where port =?";
        return queryForList(NginxServiceConfigPhp.class,sql,port);
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByServiceIdDomainPort(String serviceId,String domain,String port) {
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp where serviceId =? and  domain =? and  port =?";
        return queryForList(NginxServiceConfigPhp.class,sql,serviceId,domain,port);
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByProjectModuleId(String projectModuleId) {
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp where projectModuleId =?";
        return queryForList(NginxServiceConfigPhp.class,sql,projectModuleId);
    }
    @Override
    public List<NginxServiceConfigPhp> queryNginxServiceConfigPhpsByProjectModuleIdAndDeployEnvId(String projectModuleId,String deployEnvId){
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp where projectModuleId =? and deployEnvId = ?";
        return queryForList(NginxServiceConfigPhp.class,sql,projectModuleId,deployEnvId);
    }
    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_nginxServiceConfigPhp";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<NginxServiceConfigPhp> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`serverId`,`serviceId`,`deployEnvId`,`domain`,`port`,`workDirectory`,`use`,`projectId`,`projectModuleId` from t_nginxServiceConfigPhp limit ?,?";
        return queryForList(NginxServiceConfigPhp.class,sql,begin,pageSize);
    }
}
